home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / lib / python2.4 / test / test_pep277.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2005-10-18  |  4KB  |  131 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.4)
  3.  
  4. import sys
  5. import os
  6. import unittest
  7. from test import test_support
  8. if not os.path.supports_unicode_filenames:
  9.     raise test_support.TestSkipped, 'test works only on NT+'
  10.  
  11. filenames = [
  12.     'abc',
  13.     u'ascii',
  14.     u'Gr\xc3\xbc\xc3\x9f-Gott',
  15.     u'\xce\x93\xce\xb5\xce\xb9\xce\xac-\xcf\x83\xce\xb1\xcf\x82',
  16.     u'\xd0\x97\xd0\xb4\xd1\x80\xd0\xb0\xd0\xb2\xd1\x81\xd1\x82\xd0\xb2\xd1\x83\xd0\xb9\xd1\x82\xd0\xb5',
  17.     u'\xe3\x81\xab\xe3\x81\xbd\xe3\x82\x93',
  18.     u'\xd7\x94\xd7\xa9\xd7\xa7\xd7\xa6\xd7\xa5\xd7\xa1',
  19.     u'\xe6\x9b\xa8\xe6\x9b\xa9\xe6\x9b\xab',
  20.     u'\xe6\x9b\xa8\xd7\xa9\xe3\x82\x93\xd0\xb4\xce\x93\xc3\x9f']
  21.  
  22. def deltree(dirname):
  23.     if os.path.exists(dirname):
  24.         for fname in os.listdir(unicode(dirname)):
  25.             os.unlink(os.path.join(dirname, fname))
  26.         
  27.         os.rmdir(dirname)
  28.     
  29.  
  30.  
  31. class UnicodeFileTests(unittest.TestCase):
  32.     files = [ os.path.join(test_support.TESTFN, f) for f in filenames ]
  33.     
  34.     def setUp(self):
  35.         
  36.         try:
  37.             os.mkdir(test_support.TESTFN)
  38.         except OSError:
  39.             pass
  40.  
  41.         for name in self.files:
  42.             f = open(name, 'w')
  43.             f.write((name + '\n').encode('utf-8'))
  44.             f.close()
  45.             os.stat(name)
  46.         
  47.  
  48.     
  49.     def tearDown(self):
  50.         deltree(test_support.TESTFN)
  51.  
  52.     
  53.     def _apply_failure(self, fn, filename, expected_exception, check_fn_in_exception = True):
  54.         
  55.         try:
  56.             fn(filename)
  57.             raise test_support.TestFailed("Expected to fail calling '%s(%r)'" % (fn.__name__, filename))
  58.         except expected_exception:
  59.             details = None
  60.             if check_fn_in_exception and details.filename != filename:
  61.                 raise test_support.TestFailed("Function '%s(%r) failed with bad filename in the exception: %r" % (fn.__name__, filename, details.filename))
  62.             
  63.         except:
  64.             details.filename != filename
  65.  
  66.  
  67.     
  68.     def test_failures(self):
  69.         for name in self.files:
  70.             name = 'not_' + name
  71.             self._apply_failure(open, name, IOError)
  72.             self._apply_failure(os.stat, name, OSError)
  73.             self._apply_failure(os.chdir, name, OSError)
  74.             self._apply_failure(os.rmdir, name, OSError)
  75.             self._apply_failure(os.remove, name, OSError)
  76.             self._apply_failure(os.listdir, name, OSError, False)
  77.         
  78.  
  79.     
  80.     def test_open(self):
  81.         for name in self.files:
  82.             f = open(name, 'w')
  83.             f.write((name + '\n').encode('utf-8'))
  84.             f.close()
  85.             os.stat(name)
  86.         
  87.  
  88.     
  89.     def test_listdir(self):
  90.         f1 = os.listdir(test_support.TESTFN)
  91.         f2 = os.listdir(unicode(test_support.TESTFN, sys.getfilesystemencoding()))
  92.         f2.sort()
  93.         print f2
  94.  
  95.     
  96.     def test_rename(self):
  97.         for name in self.files:
  98.             os.rename(name, 'tmp')
  99.             os.rename('tmp', name)
  100.         
  101.  
  102.     
  103.     def test_directory(self):
  104.         dirname = os.path.join(test_support.TESTFN, u'Gr\xc3\xbc\xc3\x9f-\xe6\x9b\xa8\xe6\x9b\xa9\xe6\x9b\xab')
  105.         filename = u'\xc3\x9f-\xe6\x9b\xa8\xe6\x9b\xa9\xe6\x9b\xab'
  106.         oldwd = os.getcwd()
  107.         os.mkdir(dirname)
  108.         os.chdir(dirname)
  109.         f = open(filename, 'w')
  110.         f.write((filename + '\n').encode('utf-8'))
  111.         f.close()
  112.         print repr(filename)
  113.         os.access(filename, os.R_OK)
  114.         os.remove(filename)
  115.         os.chdir(oldwd)
  116.         os.rmdir(dirname)
  117.  
  118.  
  119.  
  120. def test_main():
  121.     
  122.     try:
  123.         test_support.run_unittest(UnicodeFileTests)
  124.     finally:
  125.         deltree(test_support.TESTFN)
  126.  
  127.  
  128. if __name__ == '__main__':
  129.     test_main()
  130.  
  131.